#include "lambert.h"

#include <cmath>

namespace raytrace {
  
Lambert::Lambert(Vector3Arg reflectance_color,
                 Vector3Arg emittance_color)
  : Material(reflectance_color, emittance_color) {
}

void Lambert::GetOutDirection(Vector3Arg in, Vector3Arg normal, uint32_t depth,
                              std::vector<float>& ipdfs,
                              std::vector<Vector3>& outs) const {
	const Vector3 nl = Vector3::scale(normal,
                                    Vector3::dot(normal, in) < 0 ? 1.0f : -1.0f);

	float pdf;
	const Vector3 d = Material::GetPointOnHemisphere(nl, pdf);
  
  outs.push_back(d);
  ipdfs.push_back(Vector3::dot(nl, d) / pdf);
}

}
